home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 11 / Info-Mac_XI_Disc_1.cdr_ / Info-Mac XI Disc 1.cdr / Programs / Science & Math / MacEspresso 1.0 / espresso / cvrmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-26  |  3.0 KB  |  134 lines  |  [TEXT/R*ch]

  1. #include "espresso.h"
  2.  
  3.  
  4. /* cost -- compute the cost of a cover */
  5. void cover_cost(F, cost)
  6. IN pcover F;
  7. INOUT pcost cost;
  8. {
  9.     register pcube p, last;
  10.     pcube *T;
  11.     int var;
  12.  
  13.     /* use the routine used by cofactor to decide splitting variables */
  14.     massive_count(T = cube1list(F));
  15.     free_cubelist(T);
  16.  
  17.     cost->cubes = F->count;
  18.     cost->total = cost->in = cost->out = cost->mv = cost->primes = 0;
  19.  
  20.     /* Count transistors (zeros) for each binary variable (inputs) */
  21.     for(var = 0; var < cube.num_binary_vars; var++)
  22.     cost->in += cdata.var_zeros[var];
  23.  
  24.     /* Count transistors for each mv variable based on sparse/dense */
  25.     for(var = cube.num_binary_vars; var < cube.num_vars - 1; var++)
  26.     if (cube.sparse[var])
  27.         cost->mv += F->count * cube.part_size[var] - cdata.var_zeros[var];
  28.     else
  29.         cost->mv += cdata.var_zeros[var];
  30.  
  31.     /* Count the transistors (ones) for the output variable */
  32.     if (cube.num_binary_vars != cube.num_vars) {
  33.     var = cube.num_vars - 1;
  34.     cost->out = F->count * cube.part_size[var] - cdata.var_zeros[var];
  35.     }
  36.  
  37.     /* Count the number of nonprime cubes */
  38.     foreach_set(F, last, p)
  39.     cost->primes += TESTP(p, PRIME) != 0;
  40.  
  41.     /* Count the total number of literals */
  42.     cost->total = cost->in + cost->out + cost->mv;
  43. }
  44.  
  45.  
  46. /* fmt_cost -- return a string which reports the "cost" of a cover */
  47. char *fmt_cost(cost)
  48. IN pcost cost;
  49. {
  50.     static char s[200];
  51.  
  52.     if (cube.num_binary_vars == cube.num_vars - 1)
  53.     (void) sprintf(s, "c=%d(%d) in=%d out=%d tot=%d",
  54.         cost->cubes, cost->cubes - cost->primes, cost->in,
  55.         cost->out, cost->total);
  56.     else
  57.     (void) sprintf(s, "c=%d(%d) in=%d mv=%d out=%d",
  58.        cost->cubes, cost->cubes - cost->primes, cost->in,
  59.        cost->mv, cost->out);
  60.     return s;
  61. }
  62.  
  63.  
  64. char *print_cost(F)
  65. IN pcover F;
  66. {
  67.     cost_t cost;
  68.     cover_cost(F, &cost);
  69.     return fmt_cost(&cost);
  70. }
  71.  
  72.  
  73. /* copy_cost -- copy a cost function from s to d */
  74. void copy_cost(s, d)
  75. pcost s, d;
  76. {
  77.     d->cubes = s->cubes;
  78.     d->in = s->in;
  79.     d->out = s->out;
  80.     d->mv = s->mv;
  81.     d->total = s->total;
  82.     d->primes = s->primes;
  83. }
  84.  
  85.  
  86. /* size_stamp -- print single line giving the size of a cover */
  87. void size_stamp(T, name)
  88. IN pcover T;
  89. IN char *name;
  90. {
  91.     printf("# %s\tCost is %s\n", name, print_cost(T));
  92.     (void) fflush(stdout);
  93. }
  94.  
  95.  
  96. /* print_trace -- print a line reporting size and time after a function */
  97. void print_trace(T, name, time)
  98. pcover T;
  99. char *name;
  100. long time;
  101. {
  102.     printf("# %s\tTime was %s, cost is %s\n",
  103.     name, print_time(time), print_cost(T));
  104.     (void) fflush(stdout);
  105. }
  106.  
  107.  
  108. /* totals -- add time spent in the function into the totals */
  109. void totals(time, i, T, cost)
  110. long time;
  111. int i;
  112. pcover T;
  113. pcost cost;
  114. {
  115.     time = ptime() - time;
  116.     total_time[i] += time;
  117.     total_calls[i]++;
  118.     cover_cost(T, cost);
  119.     if (trace) {
  120.     printf("# %s\tTime was %s, cost is %s\n",
  121.         total_name[i], print_time(time), fmt_cost(cost));
  122.     (void) fflush(stdout);
  123.     }
  124. }
  125.  
  126.  
  127. /* fatal -- report fatal error message and take a dive */
  128. void fatal(s)
  129. char *s;
  130. {
  131.     fprintf(stderr, "espresso: %s\n", s);
  132.     exit(1);
  133. }
  134.